#{extends 'main.html' /}

<h2><a style ="color:#400040;" href = "@{Projects.showProject((Long)project.getEntityId())}">${project.name}</a> > <a href = "@{UserStories.listStories(project.getEntityId())}" style ="color:#400040;">User Stories</a> > Application Roles</h2>
<hr/>

#{if controllers.Security.checkPermission("Create/edit/delete application roles in my project ",project)}<a href="create/${projectId}/0">+ Add New Role</a>
#{if allAppRoles}
<br/>
<br/>
#{list items:allAppRoles, as:'appRole'}<a href="javascript:deleteRole('${appRole.userStories.appRoles.size()}','${appRole.userStories.size()}')" class = "link" title="delete?" style="color:red">x</a>
<a class = "link" href="${appRole.getEntityId()}/${projectId}" title="edit?"><img src="/public/images/edit-icon.png" border=0></a>&nbsp;&nbsp;&nbsp;${appRole.name}
<br/>
#{/list}
<script>
    $(function(){
        $(".link").tipTip();
    });
    function deleteRole(size, userstories){
        if (size != 1) {
            showDialogHelper('Confirmation', 'This application role is associated to ' + userstories + ' stories. Are you sure you want to delete this role?', true, 'delete/${appRole.getEntityId()}/${projectId}', 'prompt');
        }
        else {
            showDialogHelper('Error!', 'This application role cannot be deleted because it is the only role associated to its user story. A user story must be associated to at least 1 application role.', false, '', 'error');
        }
    }
</script>

#{/if}
#{else}
#{list items:allAppRoles, as:'appRole'}
- ${appRole.name}
<br/>
#{/list}
<br/>
#{/else}
#{/if}
#{else}
	There are currently no application roles.
#{/else}
